Adding parameters will always improve a model's fit as measured by R^2^.
knitr::opts_chunk$set( fig.align='center', dpi = 150, include=FALSE, echo=FALSE, message=FALSE, warning=FALSE )
library(magrittr) library(modelr) library(tidyverse) file_r2 <- paste(dir_images, "r2_explained.png", sep = "/") file_r2v2 <- paste(dir_images, "r_squared_formula.png", sep = "/")
knitr::include_graphics(file_r2)
Note that the classic formula for R^2^ seen below is derived from the formula seen above.
knitr::include_graphics(file_r2v2) # image from http://www.simages.org/r-squared-formula/
m1 <- lm(mpg ~ drat, data = mtcars) rsquare(m1, mtcars) m3 <- lm(mpg ~ drat + wt + hp, data = mtcars) rsquare(m3, mtcars)
mtcars %<>% add_residuals(m1, var = "resid1") %>% add_residuals(m3, var = "resid3") %>% gather(resid1, resid3, key = resid_type, value = resid_value) ggplot(mtcars) + geom_hline(yintercept = 0) + geom_point(aes(x = wt, y = resid_value), color = "red") + facet_grid(~resid_type)
The sum of squared errors (SSE) sums the difference between the actual data and the predicted values. SSE represents unexplained variation
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.